// pages/nav/nav.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    array: [],
    entity: null,
    permission:[]    
  },
  //实体变化
  changeEntity: function (e) {
    let index = e.detail.value
    let name = this.data.array[index].name
    getApp().globalData.companyId = this.data.array[index].id
    // console.log(this.data.array[index])
    this.setData({
      entity: name
    })
    this.getPermission(getApp().globalData.companyId)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    console.log(getApp().globalData.companys[0])
    this.setData({
      array: getApp().globalData.companys,
      entity: getApp().globalData.companys[0].name
    })    
    getApp().globalData.companyId = getApp().globalData.companys[0].id
    this.getPermission(getApp().globalData.companyId)  
    console.log(getApp().globalData)  
  },
  logout: function(){
    wx.setStorageSync('username', '')
    wx.setStorageSync('password', '')
    wx.redirectTo({
      url: '/pages/login/login',
    })
    getApp().globalData.companys = []
  },
  getPermission: function(cid){
    wx.showLoading({
      title:'加载中',
      mask: true
    })
    let _self = this
    getApp().baseInfo('client/report/company/' + cid + '/permission/list', function (res) {
      console.log(res.data)
      wx.hideLoading()
      _self.setData({
        permission: res.data.data
      })
    })
  },
  /**
   * 点击进入营业概况报表页
   */
  goBusiness: function (e) {
    if (e.currentTarget.dataset.group === 'group'){
      wx.navigateTo({
        url: '/pages/business_group/business',
      })
    }else{
      wx.navigateTo({
        url: '/pages/list_business/business',
      })
    }    
  },
  /**
   * 点击进入营业概况报表页
   */
  goCard: function (e) {
    if (e.currentTarget.dataset.group === 'group') {
      wx.navigateTo({
        url: '/pages/card_group/list_card',
      })
    } else {
      wx.navigateTo({
        url: '/pages/list_card/list_card',
      })
    } 
  },
  /**
   * 点击进入营业概况报表页
   */
  goChief: function () {
    wx.navigateTo({
      url: '/pages/chief/chief',
    })
  },
  /**
   * 点击进入营业概况报表页
   */
  goGoods: function () {
    wx.navigateTo({
      url: '/pages/list_goods/list_goods',
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})